using System;
using System.Collections.Generic;
using System.Text;
using Project.Practice.MVP.ExceptionHandling.CustomException;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
namespace Project.Practice.MVP.DataAccess
{
    /// <summary>
    /// every tier has its feature method and ProcessDataAccessLayerException()
    ///
    /// try
    /// {
    ///      feature method
    /// }
    /// catch(Exceptiion ex)
    /// {
    ///     ProcessDataAccessLayerException(ex);
    /// }
    /// </summary>
    public partial class DataProvider
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public static void ProcessDataAccessLayerException(Exception ex)
        {
            bool reThrow = false;
            if (ex.GetType().Equals(typeof(CriticalException)) == true)
            {
                // "Propogate Policy" will rethrow exception in exception chain
                reThrow = ExceptionPolicy.HandleException(ex, "Propogate Policy");
                if (reThrow)
                {
                    throw ex;
                }
            }
            else if (ex.GetType().Equals(typeof(SQLDALException)) == true)
            {
                reThrow = ExceptionPolicy.HandleException(ex, "Propogate Policy");
                if (reThrow)
                {
                    throw ex;
                }
            }
            else
            {
                reThrow = ExceptionPolicy.HandleException(ex, "DataAccess Layer Policy");
                if (reThrow)
                {
                    throw ex;
                }
            }

        } 

    }
}
